package com.fz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.entity.Complain;
import com.fz.mapper.ComplainMapper;
import com.fz.service.ComplainService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 存储住户投诉信息 服务实现类
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@Service
public class ComplainServiceImpl extends ServiceImpl<ComplainMapper, Complain> implements ComplainService {
    @Resource
    ComplainMapper ComplainMapper;
    @Override
    public Boolean reject(Long id,Integer statue,Integer statu){
        return this.updateById(new Complain(id,statue,statu));
    }
    @Override
    public boolean check(Long id,String field,String value)
    {
        QueryWrapper<Complain> wrapper=new QueryWrapper<>();
        wrapper.eq(field,value);
        System.out.println(id);
        if(null!=id)
        {
            wrapper.ne("id",id);
        }
        return this.count(wrapper)==0;
    }
    @Override
    public Boolean pass(Long id,Integer status,Integer statu){return this.updateById(new Complain(id,status,statu));}
    @Override
    public List<Complain> search(String input){
        QueryWrapper<Complain> wrapper=new QueryWrapper<>();
        wrapper.like("type",input);
        return this.list(wrapper);
    }
    @Override
    public boolean del(Long id, Integer status) {
        return this.updateById(new Complain(id,status));
    }

    @Override
    public Page<Complain> getList(Long userId, Integer pageNo, Integer pageSize) {
        QueryWrapper<Complain> wrapper = new QueryWrapper<>();
        Page<Complain>ComplainPage;
        wrapper.eq("user_id", userId)
                .ne("status",3)
                .orderByDesc("create_time");
        ComplainPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return ComplainPage;
    }

    @Override
    public Boolean add(Long userId, String type, String content){

        return this.save(new Complain(userId,type,content));
    }
    @Override
    public Page<Complain> search(String input, Integer pageNo, Integer pageSize){
        QueryWrapper<Complain> wrapper=new QueryWrapper<>();
        Page<Complain>repairPage;
        wrapper.like("type",input)
                .ne("status",3)
                .orderByDesc("create_time");
        repairPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return this.page(new Page<>(pageNo, pageSize),wrapper);
    }
    @Override
    public Page<Complain> showList(Integer pageNo, Integer pageSize) {
        QueryWrapper<Complain> wrapper = new QueryWrapper<>();
        Page<Complain>repairPage;
        wrapper.ne("status",3)
                .orderByDesc("create_time");
        repairPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return this.page(new Page<>(pageNo, pageSize),wrapper);
    }
}
